<script setup lang="ts">
let container = ref<HTMLElement>()
let changeArea = ref(false)

function changeAreaFn (bool: boolean) {
  if(changeArea.value === bool) return
  changeArea.value = bool
  if(changeArea.value) {
    (container.value?.style as  CSSStyleDeclaration).gridTemplateAreas = `"header header" "sidebar main" "sidebar footer"`
  } else {
    (container.value?.style as  CSSStyleDeclaration).gridTemplateAreas = `"header header" "sidebar main" "footer footer"`;
  }
}
</script>

<template>
<div class="wrap">
  <section>
    <div class="container" ref="container">
      <header>header</header>
      <main>main</main>
      <aside>Sidebar</aside>
      <footer>Footer</footer>
    </div>
  </section>

  <form action="">
    <div @click="changeAreaFn(false)" class="controle">
      <input type="radio" name="area" id="area__before" checked>
      <label  for="area__before">grid-template-areas: "header  header" "sidebar main" "footer footer"</label>
    </div>
    <div @click="changeAreaFn(true)" class="controle">
      <input type="radio" name="area" id="area__after">
      <label for="area__after">grid-template-areas: "header header" "sidebar main" "sidebar footer"</label>
    </div>
  </form>
</div>
</template>

<style scoped lang="scss">
.wrap {
  width: 100vw;
  min-height: 100vh;
  font-family: "Exo", Arial, sans-serif;
  background-color: #557;
  color: #fff;
  display: grid;
  place-content: center;
  padding: 1rem;
  section {
    max-width: 80vw;
    width: 100%;
    margin: 0 auto;
    min-height: calc(80vh - 40px);
    display: flex;
    justify-content: center;

    .container {
      display: grid;
      grid-template-columns: 200px 1fr;
      grid-template-rows: 80px 1fr 60px;
      grid-gap: 1rem;
      width: 100%;
      grid-template-areas:
        "header  header"
        "sidebar  main"
        "footer  footer"
      ;
      transition: all 0.2s linear;


      border: 1px dashed #f36;
      box-shadow: 0 0 0 6px rgb(0 0 0 / 13%);
      border-radius: 1px;

      & > * {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 10px;
        gap: 5px;
        color: #fff;
        font-size: 1.2rem;
        text-shadow: 1px 1px 0 rgb(0 0 0 / 0.5);
      }
      header {
        background-color: #f1c2c6;
        grid-area: header;
      }

      aside {
        background-color: #dac2f1;
        grid-area: sidebar;
      }

      main {
        background-color: #ccf1c2;
        grid-area: main;
      }

      footer {
        background-color: #c2e9f1;
        grid-area: footer;
      }
    }

    form {
      display: flex;
      justify-content: center;
      align-content: center;
      flex-direction: column;
      padding-top: 20px;
      gap: 10px;

      label {
        display: inline-flex;
        align-items: center;
        gap: 5px;
      }
    }
  }
}
</style>
